<template>
  <div class="my-tag">
    <input v-if="isEdit" v-focus @blur="isEdit = false" @keyup.enter="updTag" :value="value"
      class="input" type="text" placeholder="输入标签" />
    <div v-else class="text" @click="isEdit = true">{{ value }}</div>
  </div>
</template>

<script>
export default {
  props: {
    value: String,
  },
  data() {
    return {
      isEdit: false,
    };
  },
  methods: {
    updTag(e) {
      if (e.target.value === "") {
        alert("请输入标签，不能为空");
        return;
      }
      this.$emit("input", e.target.value);
      this.isEdit = false;
    },
  },
};
</script >

<style lang="less" scoped>
.my-tag {
  cursor: pointer;
  .input {
    appearance: none;
    outline: none;
    border: 1px solid #ccc;
    width: 100px;
    height: 40px;
    box-sizing: border-box;
    padding: 10px;
    color: #666;
    &::placeholder {
      color: #666;
    }
  }
}
</style>